<?php 
    session_start();
    if($_SESSION['uid']==""||$_SESSION['level']!=3){
		header("Location: ../exit.php");
		exit();
	}
    include('/tool/submitValidate.php');
	include('/tool/pdo.php');
	include('/class/apartment.class.php');
	include('/class/dormitory-allocating.class.php');
	include('/class/public-data.class.php');
	include('/bll/PublicDataBLL.php');
    include('/bll/DormitoryAllocatingBLL.php');
    
    $action = isset($_POST['action']) ? $_POST['action'] : 0;
    $data = isset($_POST['data']) ? $_POST['data'] : 0;

    $message=array();
    switch((int)$action){
        //分配宿舍管理权限
        case 1:
            $dormitoryList=json_decode($data);
            if($dormitoryList!=null){
                $dormitoryAllocatingBLL=new DormitoryAllocatingBLL();
                $message=$dormitoryAllocatingBLL->instructorAllocatingDormitories($dormitoryList);
            }
            break;
        //移除宿舍管理权限
        case 2:
        $dormitoryList=json_decode($data);
            if($dormitoryList!=null){
                $dormitoryAllocatingBLL=new DormitoryAllocatingBLL();
                $message=$dormitoryAllocatingBLL->instructorAllocatingDormitoriesRemove($dormitoryList);
            }
            break;
        default:break;
    }

    echo json_encode($message,JSON_UNESCAPED_UNICODE);
?>